<?php

function greengar_whiteboard_add_xmppAccount($login, $domain, $userid) {
    
    // Remove same id of others user
    $others = greengar_whiteboard_get_xmppAccount($login, $domain, NULL);
    if($others && $others[0]/* && $others[0]->owner_guid != $userid*/) {
        $other = $others[0];
        $other->delete();
    }

    // Update old one or add this as a new one
    $currents = greengar_whiteboard_get_xmppAccount($login, $domain, $userid);
    if($currents && $currents[0]) {
        $current = $currents[0];
    } else {
        $current = new XMPPAccount();
    }

    $current->saveAccount($login, $domain);
    $current->setOwner($userid);
    return $current;
}

?>